<script setup>
import modifyView from '@/views/supplier/modify.vue'
import { showAllApi, showBackApi } from '@/api/supplier'
import { onMounted, ref } from 'vue'
const mref = ref('mref')
const tableData = ref([])
const total = ref(0)
const currentPage = ref(1)
const pageSize = ref(5)
const size = ref('default')
const background = ref(true)
const disabled = ref(false)
const showBack = async (id) => {
  let res = await showBackApi(id)
  mref.value.dialogVisible = true
  mref.value.dialogFormData = res.data
}
const handleSizeChange = (val) => {
  pageSize.value = val
  getAll()
}
const handleCurrentChange = (val) => {
  currentPage.value = val
  getAll()
}
const getAll = async () => {
  let res = await showAllApi(currentPage.value, pageSize.value)
  tableData.value = res.rows
  total.value = res.total
}
onMounted(() => {
  getAll()
})
</script>
<template>
  <modifyView ref="mref" @search="getAll" />

  <el-table :data="tableData" style="width: 100%" @selection-change="handleSelectionChange">
    <el-table-column fixed type="index" label="#" :index="indexMethod" />
    <el-table-column type="selection" width="50" />
    <el-table-column prop="supplierName" label="供应商名字" width="80" />
    <el-table-column prop="linkName" label="联系人名字" width="80" />
    <el-table-column prop="linkPhone" label="联系人手机号" width="120" />
    <el-table-column prop="address" label="详细地址" width="120" />
    <el-table-column prop="createTime" label="创建时间" width="120" />
    <el-table-column fixed="right" label="操作" min-width="120">
      <template #default="{ row }">
        <el-button type="primary" @click="showBack(row.id)">
          修改
        </el-button>
        <el-button type="danger" @click="delById(row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

  <div class="demo-pagination-block">
    <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 30, 40]"
      :size="size" :disabled="disabled" :background="background" layout="total, sizes, prev, pager, next, jumper"
      :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  </div>
</template>